\documentclass[12pt]{article}
\usepackage{times}
\usepackage{graphicx}
\usepackage{sidecap}
\usepackage{wrapfig}
\usepackage{fancyhdr}
\usepackage{amsmath}
\pagestyle{fancy}
\renewcommand{\baselinestretch}{1.2}
\newenvironment{mylisting}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting2}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting3}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting4}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting5}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting6}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\begin{document}
	\textbf{{\Huge Quark Gluon plasma Java/Ambienttalk/2 Computer Graphics supporting/system code}}
{\center{May 2, 2013, 
	Johan Ceuppens, Theo D'Hondt - Vrije Universiteit Brussel}}
\\

{\center{With thanks to : Ellie D'Hondt, the SOFT lab and the Open Source Community}}

{\large{\textbf{\center Abstract}}}
\\

	This is code which was developed for Java and Ambienttalk/2 systems to provide for computer graphics research. It is a mere illustration.


\section{ Java/Ambienttalk/2 support game code using JOGL and LWJGL}

\begin{mylisting}
\begin{verbatim}
package javablender;
/*
*
* Copyright 2012 Johan Ceuppens 
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;

public class Blender {
	private String buffer = "";
	private ModelParser2 modelparser2;

	private int[] xarray;
	private int[] yarray;
	private int[] zarray;
	private int[] carray;

	private String filename = "";

	public Blender() {
	}

	public void load(String fn)
	{
		filename = fn; 
		readinfile(filename);
		int i = 0;
		char b[] = new char[buffer.length()*10];//FIXME length
		while ( i < buffer.length()) {

			b[i] = buffer.charAt(i); 

			i++;
		}
		modelparser2 = new ModelParser2(b);	

		xarray = modelparser2.getxarray(); //returns all x coords in order
		yarray = modelparser2.getyarray(); //returns all x coords in order
		zarray = modelparser2.getzarray(); //returns all x coords in order
		carray = modelparser2.getcarray(); //returns all x coords in order


	}

	public int[] getcarray()
	{
		return carray;
	}

	public int[] getxarray()
	{
		return xarray;
	}

	public int[] getyarray()
	{
		return yarray;
	}

	public int[] getzarray()
	{
		return zarray;
	}


/***
	public static void main(String[] args)
	{
		if (args == null) {
			System.out.println("usage: java javablender/Blender <blendfilename>");
			System.exit(0);
		}
		new Blender(args[0]);
	}
***/	public void readinfile(String filename) {
	
	try {
		FileReader input  = new FileReader(filename);



		BufferedReader bufread = new BufferedReader(input);

		String line  = bufread.readLine();
		
		while (line != null) {
			buffer += line;
			buffer += "\n";
			line = bufread.readLine();	
		}

		buffer += "\n";
		bufread.close();

	}catch (IOException e) {
	}
	}


};
package javablender;
/*
*
* Copyright 2012 Johan Ceuppens 
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.util.*;

public class ModelParser2 {
	private int countstructure = 0;
	private int SDNA_index = 0;
	private int pointersize = 32;
	private String endianess = "";

	private LinkedList namesarray = new LinkedList();
	private LinkedList typesarray = new LinkedList();
	private LinkedList structuresarray = new LinkedList();
	private LinkedList vertexgroupnames = new LinkedList();
	private LinkedList vertexgroupsizes = new LinkedList();
	private LinkedList vertexgroupindices = new LinkedList();
	private LinkedList verticesx = new LinkedList();
	private LinkedList verticesy = new LinkedList();
	private LinkedList verticesz = new LinkedList();
	private LinkedList verticesc = new LinkedList();
	private int[] xs;
	private int[] ys;
	private int[] zs;
	private int[] cs;
	private String fileblockid = "";
	//buf is the file contents
	public ModelParser2(char[] buf) {
		int index = 0;
		if (parseheader(buf,index)<=0) {
			if (parsepointersize(buf,index)<=0) {
				if (parseendianess(buf,index)<=0)
					if (parseversion(buf,index) <= 0)
					 {
						for (; index < buf.length; ) { 
							if (parsefileblock(buf,index) < 0) {
				
								System.out.println("123> EOF");							
								return ;	
						}		
					}
				}
				else System.out.println("123> no endianess");	
			}else System.out.println("123> no pointer size");	
		}else System.out.println("123> no header");	

	}

	public void padbytes(int index) 
	{

		index += index%4;

	}
	
	public int[] getcarray()
	{
		return cs;
	}

	public int[] getxarray()
	{
		return xs;
	}

	public int[] getyarray()
	{
		return ys;
	}

	public int[] getzarray()
	{
		return zs;
	}


/*
 * parsing file header
 */ 
	public int parseendianess(char[] buf, int index)
	{
		char endianesschar = (char)buf[index];
		if (endianesschar == 'v') 
			endianess = "little";	
		else if (endianesschar == 'V') 
			endianess = "big";	
		index += 1;

		return 0;
	}

	public int parsespace(char[] buf,int index)
	{
		for (;buf[index++] != 32;)
			;

		return 0;
	}

	public int parseversion(char[] buf, int index)
	{
		char majorversion = (char)buf[index+0];
		char minorversion = (char)buf[index+1];
		char minorversion2 = (char)buf[index+2];
		index += 3;


		return 0;	
	}
	public int parsepointersize(char[] buf,int index)
	{

		char pointersizechar = (char)buf[index];
		index += 1;
		if (pointersizechar == '_') {
			pointersize = 32;
			return 0;
		}
		else if (pointersizechar == '-') {
			pointersize = 64;	
			return 0;
		}		
	
		return -1;
	}
	public int parseheader(char[] buf,int index)
	{

		char b = (char)buf[index+0];	
		char l = (char)buf[index+1];	
		char e = (char)buf[index+2];	
		char n = (char)buf[index+3];	
		char d = (char)buf[index+4];	
		char e2 = (char)buf[index+5];	
		char r = (char)buf[index+6];	
		System.out.println(""+b+l+e+n+d+e2+r);

		index += 6;	
		if ((""+b+l+e+n+d+e2+r) == "BLENDER")
			return 0;
		else 
			return -1;
	}
/*
 * parsing file blocks 
 */ 

	public int parsescene(char[] buf, int index)
	{
		return 0;
	}

	public int parsefileblock(char[] buf, int index) {

		int size = parsefileblockheader(buf,index);
		if (fileblockid == "DNA1")
			parseDNA(buf,index);
		else if (fileblockid.charAt(0) == 'S' && fileblockid.charAt(1) == 'C')
			parsescene(buf,index);
		else
			parsefileblockdata(buf,index,size);
	
		return 0;	
	}

	public int parsefileblockdata(char[] buf, int index, int blocksize) {
		int i;
		for (i = 0; i < blocksize; i++) {
			char c = buf[index+i];	
		}
		index += i;
		return 0;
	}

	//code is "" if you want to parse thew next fileblock
	//code is e.g. "DNA1" for searching that fileblock id
	//it can be programmed better
	public int parsefileblockheader(char[] buf, int index)
	{

		char[] id = new char[4];//4 wide
		id[0] = (char)(buf[index]);
		id[1] = (char)(buf[index+1]);
		id[2] = (char)(buf[index+2]);
		id[3] = (char)(buf[index+3]);

		fileblockid = ""+id[0]+id[1]+id[2]+id[3];	

		System.out.println("fileblockid> "+id[0]+id[1]+id[2]+id[3]);
		index += 4;
		int size;
		if (endianess == "big")
			size = buf[index]*2*2*2+buf[index+1]*2*2+buf[index+2]*2+buf[index+3]*1;
		else
			size = buf[index+3]*2*2*2+buf[index+2]*2*2+buf[index+1]*2+buf[index]*1;
		System.out.println("size> "+size);
		index += 4;
		if (pointersize == 64) {
			index+=8;
		} else if (pointersize == 32) {
			index+=4;
		}
		if (endianess == "big")
			SDNA_index = buf[index]*2*2*2+buf[index+1]*2*2+buf[index+2]*2+buf[index+3];
		else
			SDNA_index = buf[index+3]*2*2*2+buf[index+2]*2*2+buf[index+1]*2+buf[index];

		System.out.println("SDNA_index> "+SDNA_index);
			index+=8;
		if (pointersize == 64) {
			index+=pointersize;
		} else if (pointersize == 32) {
			index+=pointersize;
		}
		index += 4;
		if (endianess == "big")
			countstructure = buf[index]*2*2*2+buf[index+1]*2*2+buf[index+2]*2+buf[index+3];
		else
			countstructure = buf[index+3]*2*2*2+buf[index+2]*2*2+buf[index+1]*2+buf[index];

		System.out.println("count> " + countstructure);

		index += 12;
		if (pointersize == 64) {
			index+=pointersize;
		} else if (pointersize == 32) {
			index+=pointersize;
		}

		return size;

	}

/*
 * parsing vertices
 */

	public int parsevgroup(char[] buf, int index, int vgroupsizeindex)
	{

		Object vgroupsizeo = vertexgroupsizes.get(vgroupsizeindex);
		int vgroupsize = (int)vgroupsizeo;
		char[] chs = new char[vgroupsize];
		int j = 0;
		int i;	
		for (i = 0; i < chs.length; i+=4) {
			int xx = chs[i];	
			int yy = chs[i+1];	
			int zz = chs[i+2];	
			int cc = chs[i+3];	

			xs[j] = xx;
			ys[j] = yy;
			zs[j] = zz;
			cs[j] = cc;

		}

		index += i;

		return 0;
	}

	public int parsevgrouptype(String s)
	{
		//FIXME no [] in string
		int ii = s.indexOf('[');	
		int jj = s.indexOf(']');	
		int r = 0;
		int i = jj-1;	
		for (int j = ii+1; j < jj; j++) {

			if (s.charAt(j) >= 48 && s.charAt(j) <= 57) {
			

				r += (s.charAt(j)-48)*10*i;	
					
			}	
			i--;
		}
	
		return r;
	}	
 
	public int parsevertices(char[] buf, int index)
	{

		for (int i = 0; i < namesarray.size(); i++) {
			Object o = namesarray.get(i);	
			String s = (String)o;
			LinkedList li = new LinkedList();	
			for (int j = 0; j < typesarray.size(); j++) {
				Object o2 = typesarray.get(j);
				LinkedList l1 = (LinkedList)o2;

				Object ooo = l1.get(j);
				String s2 = (String)ooo;
				int vgroupsize = parsevgrouptype(s2);	
				li.add(vgroupsize);
				vertexgroupindices.add(j);	
			}
			vertexgroupnames.add(s);
			vertexgroupsizes.add(li);
			for (int k = 0; k < structuresarray.size(); k++) {
				Object o3 = structuresarray.get(k);
				LinkedList l2 = (LinkedList)o3;
				for (int l = 0; l < l2.size(); l++) {
					Object o4 = l2.get(k);
					LinkedList l3 = (LinkedList)o4;

					int t = 0;
					for (int m = 0; m < l3.size(); m++) {
					
						Object o5 = l3.get(m);
						int indexintype = (int)o5;	

						Object o6 = vertexgroupindices.get(t);
						int vgi = (int)o6;
						if (m == vgi) {

							for (; index < buf.length; ) {
								parsefileblockheader(buf,index);
								if (fileblockid == s) {
									parsevgroup(buf,index,vgi);
									break;//FIXME	
								}
							}		

						}						

	
					}
				}	
							

			}
		}
		return 0;
	}


	public int parseverticesnooffset(char[] buf, int index)
	{
		//padbytes(index);
		int j = 0;
		xs = new int[buf.length-index];//FIXME length	
		ys = new int[buf.length-index];	
		zs = new int[buf.length-index];	
		cs = new int[buf.length-index];	

		for (int i = index; j < countstructure; ) {//FIXME 17

			int xx = 0, yy = 0, zz = 0, cc = 0;

			if (buf[i] == 32 ) {//FIXME EOF
				i++;
				int k,l;

				for (k = i; buf[k] != 32; k++)
					; 
				
				for (l = i; l < k; l++) {	 
					xx += 10*(k-l)*(buf[l]-47);//convert ascii code
				}	
				i = l;		
					
			}
	
			else {
				i++;
				continue;
			}		

			if (buf[i] == 32 ) {//FIXME EOF
				i++;
				int k,l;

				for (k = i; buf[k] != 32; k++)
					; 
				
				for (l = i; l < k; l++) {	 
					yy += 10*(k-l)*(buf[l]-47);//convert ascii code
				}	
				i = l;		
					
			}
	
			else {
			}		
			if (buf[i] == 32 ) {//FIXME EOF
				i++;
				int k,l;

				for (k = i; buf[k] != 32; k++)
					; 
				
				for (l = i; l < k; l++) {	 
					zz += 10*(k-l)*(buf[l]-47);//convert ascii code
				}	
				i = l;		
					
			}
	
			else {
			}		
			if (buf[i] == 32 ) {//FIXME EOF
				i++;
				int k,l;

				for (k = i; buf[k] != 32; k++)
					; 
				
				for (l = i; l < k; l++) {	 
					cc += 10*(k-l)*(buf[l]-47);//convert ascii code
				}	
				i = l;		
					
			}
	
			else {
			}	

			System.out.println("x= "+xx+" y="+yy+" z="+zz+" c="+cc);	
				
			xs[j] = xx;
			ys[j] = yy;
			zs[j] = zz;
			cs[j] = cc;
			j++;
		}
		return 0;
	}

	public int parseDNA(char[] buf, int index)
	{
		char[] id = new char[8];
		id[0] = buf[index];
		id[1] = buf[index+1];
		id[2] = buf[index+2];
		id[3] = buf[index+3];
		id[4] = buf[index+4];
		id[5] = buf[index+5];
		id[6] = buf[index+6];
		id[7] = buf[index+7];
		System.out.println("DNAindex added, SC> "+id[0]+id[1]+id[2]+id[3]+id[4]+id[5]+id[6]+id[7]);
		//if (id[0] == 'D' && id[1] == 'N' && id[2] == 'A' && id[3] == '1') {

			index += 8;

			int namesn;

			if (endianess == "big")
				namesn = 2*2*2*buf[index]+2*2*buf[index+1]+2*buf[index+2]+1*buf[index+3];
			else
				namesn = 2*2*2*buf[index+3]+2*2*buf[index+2]+2*buf[index+1]+1*buf[index];
			System.out.println("namesn> "+namesn);
			for (int i = 0; i < namesn; i++) {
				int j;
				String s = "";
				for (j = 0;;j++ ) {

					char c = buf[index+j];
					s += c;
					System.out.println("DNAname> "+c);
					if (c == '\0') {

						namesarray.add(s);	
						break;
					}	
				} 
				index += j+1;	
				index += 4;//'TYPE'
				
				int typesn;
				if (endianess == "big")
					typesn = 2*2*2*buf[index]+2*2*buf[index+1]+2*buf[index+2]+1*buf[index+3];
				else
					typesn = 2*2*2*buf[index+3]+2*2*buf[index+2]+2*buf[index+1]+1*buf[index];
				LinkedList li = new LinkedList();
				for (int k = 0; k < typesn; k++) {
					int o;
					String s2 = "";
					for (o = 0;;o++ ) {

						char c = buf[index+o];
						s2 += c;
						System.out.println("TYPEname> "+c);
						if (c == '\0') {
							li.add(s2);
							break;
						}	
					} 
					index += o+1;	

					index +=2;
					index += 4;//length id
				}
				typesarray.add(li);	
				for (int k = 0; k < typesn; k++) {

					index += 6; //length in bytes + 'STRC'		
							
					int structuresn;	
					if (endianess == "big")
						structuresn = 2*2*2*buf[index+0]+2*2*buf[index+1]+2*buf[index+2]+1*buf[index+3];
					else 
						structuresn = 2*2*2*buf[index+3]+2*2*buf[index+2]+2*buf[index+1]+1*buf[index+0];
					LinkedList li2 = new LinkedList();
					for (int l = 0; l < structuresn; l++) {
					
						index+=2;	
						int fieldsn;
						if (endianess == "big")
							fieldsn = buf[index]*2*2*2+buf[index+1]*2*2+buf[index+2]+2*buf[index+1]+1*buf[index];	
						else
							fieldsn = buf[index+3]*2*2*2+buf[index+2]*2*2+buf[index+1]+2*buf[index+1]+1*buf[index];	

							int p;
							LinkedList li3 = new LinkedList();
							for (p = 0; p < fieldsn ;p++ ) {
								int indexintype;

								if (endianess == "big") 
									indexintype = 2*buf[index+1]+1*buf[index];	
								else
									indexintype = 2*buf[index+1]+1*buf[index];	
								li3.add(indexintype);	
							}
								
							index += 2;
							li2.add(li3);	
						}
						structuresarray.add(li2);	
						index += 2;//for structuresn end	
					}	
				

			}

			return 0;
	//	}	
	//	return -1;
	}

};
package javablender;
/*
*
* Copyright 2012 Johan Ceuppens 
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class ModelParser {
	private int bufindex = 0;

	private int pointersize = 32;
	private String endianess = "";

	public ModelParser(String buf) {
		if (parseheader(buf)==0)
			if (parsepointersize(buf)==0)
				if (parseendianess(buf)==0)
					return;	
	

	}

	public int parseendianess(String buf)
	{
		char endianesschar = buf.charAt(bufindex);
		if (endianesschar == 'v') 
			endianess = "little";	
		else if (endianesschar == 'v') 
			endianess = "big";	
		bufindex += 1;
		return 0;
	}
	public int parseversion(String buf)
	{
		int majorversion = buf.charAt(bufindex+0);
		int minorversion = buf.charAt(bufindex+1);
		int minorversion2 = buf.charAt(bufindex+2);
		bufindex += 3;
		return 0;	
	}
	public int parsepointersize(String buf)
	{

		char pointersizechar = buf.charAt(bufindex);
		bufindex += 1;
		if (pointersizechar == '_') {
			pointersize = 32;
			return 0;
		}
		else if (pointersizechar == '-') {
			pointersize = 64;	
			return 0;
		}		
	
		return -1;
	}
	public int parseheader(String buf)
	{

		char b = buf.charAt(bufindex+0);	
		char l = buf.charAt(bufindex+1);	
		char e = buf.charAt(bufindex+2);	
		char n = buf.charAt(bufindex+3);	
		char d = buf.charAt(bufindex+4);	
		char e2 = buf.charAt(bufindex+5);	
		char r = buf.charAt(bufindex+6);	

		bufindex += 6;	
		if (""+b+l+e+n+d+e2+r == "BLENDER")
			return 0;
		else 
			return -1;
	}
};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.awt.Toolkit;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import java.util.*;

class BoundingBox 
{
protected float mapx, mapy, mapz, mapw, maph, mapd;

public BoundingBox(float startx, float starty, float startz, float startw, float starth, float startd)
{
	mapx = startx;
	mapy = starty;
	mapz = startz;
	mapw = startw;
	maph = starth;
	mapd = startd;
}

public float getx()
{
	return mapx;
}

public float gety()
{
	return mapy;
}

public float getz()
{
	return mapz;
}

public float getw()
{
	return mapw;
}

public float geth()
{
	return maph;
}

public float getd()
{
	return mapd;
}

public void moveleftx() 
{
	mapx--;
}
public void moverightx() 
{
	mapx++;
}
public void movelefty() 
{
	mapy--;
}
public void moverighty() 
{
	mapy++;
}
public void moveleftz() 
{
	mapz--;
}
public void moverightz() 
{
	mapz++;
}

};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.awt.Toolkit;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import java.util.*;

class BulletBase extends BoundingBox
{
protected String direction = "leftx";
public BulletBase(float startx, float starty, float startz, float startw, float starth, float startd, String dir)
{
	super(startx,starty,startz,startw,starth,startd);

	direction = dir;
	
}

public void move()
{
	if (direction == "leftx") {
		moveleftx();
	}
	else if (direction == "rightx") {
		moverightx();
	}
	else if (direction == "lefty") {
		movelefty();
	}
	else if (direction == "righty") {
		moverighty();
	}
	else if (direction == "leftz") {
		moveleftz();
	}
	else if (direction == "rightz") {
		moverightz();
	}
}

};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.awt.Toolkit;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import java.util.*;

class Bullet extends BulletBase
{
protected String fileprefix = "./pics/";
protected Image bulletimage = new ImageIcon(fileprefix+"bullet-20x20-1.png").getImage();
public Bullet(float startx, float starty, float startz, float startw, float starth, float startd, String dir)
{
	super(startx,starty,startz,startw,starth,startd,dir);
	/////bulletimage = new ImageIcon(fileprefix+"bullet-20x20-1.png").getImage();
}

public Image getImage()
{
	return bulletimage;
}
};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.util.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;

public class BulletModel extends ModelGen {

	public BulletModel(int ww, int hh, int padsz) {
		super(ww,hh,padsz);	
		generatesphere(100.0f,48);

	}

	public void move() {
		vertices.clear();
		generatesphere(100.0f,48);	
	}

};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.nio.ByteBuffer;

import javax.imageio.ImageIO;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;

import java.awt.Frame;
import java.awt.event.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;
import javax.media.opengl.glu.GLU;
import java.util.*;
import java.io.*;
import javablender.*;

public class Game implements GLEventListener,KeyListener {

	GLAutoDrawable drawabletemp;

	private int fadingcounter = 0;
	Font titlescreenfont = new Font("Helvetica", Font.BOLD, 25);
	Font titlescreenfont2 = new Font("Helvetica", Font.BOLD, 15);
	private int levelnumber = 1000;

    private float theta = (float)0.0;
    private float fraci = (float)0.0;
    private float s = 0;
    private float c = 0;
	private String configprefix = "./config/";
	private String prefix = "./pics/";
	Blender blenderfilereader = new Blender();
	
	private LinkedList terrainpieces = new LinkedList();;
	private LinkedList modelpieces = new LinkedList();;
	private LinkedList bullets = new LinkedList();;
static	private int[] xarray;
static	private int[] yarray;
static	private int[] zarray;
static	private int[] carray;
	private boolean showtitlescreen = false; 
	private int update = 0;//integer value which update should be performed (e.g. through keyboard, see KeyAdapter) 
	int width,height;
	private float dz = 0.0f;
	private BufferedImage imgImg;
	private BufferedImage bufferedImage;
	WritableRaster raster;
        ByteBuffer bb;
    public static void main(String[] args) {
	System.out.println("Loading..please wait until the window opens...");
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);
        GLCanvas canvas = new GLCanvas(caps);

/*
	public class JoglEventListener implements GLEventListener, KeyListener {
		private GLCanvas = canvas;

		public JoglEventListener(GLCanvas canvas) {
			this.canvas = canvas;
		}
	}

	JoglEventListener listener = new JoglEventListener(canvas);
	canvas.addGLEventListener(listener);
	canvas.addKeyListener(listener);
*/
	Frame frame = new Frame("Space Odyssey 3D");
        frame.setSize(320, 200);
        frame.add(canvas);
        frame.setVisible(true);
	
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
	Game game = new Game();
        canvas.addGLEventListener(game);
	canvas.addKeyListener(game);
        Object o = new Animator(canvas);
        Animator animator = (Animator)o;
        animator.add(canvas);
        animator.start();
    }

	public void loadLevel1000() {
	        GL2 gl = drawabletemp.getGL().getGL2();
		TerrainGen tp = new TerrainPieceWalkingTube(320,200,4,GL2.GL_LINES);
		TerrainGen tp2 = new TerrainPiecePillar(0,0,0,63,100,4,GL2.GL_POINTS);
		terrainpieces.add(tp);
		terrainpieces.add(tp2);

		//ModelGen mg = new 


	}

/*
 * Game configuration from config file
 */

	public void loadConfiguration(String filename)
	{

		LinkedList configlst = new LinkedList();
		try {
			FileReader input  = new FileReader(filename);

			BufferedReader bufread = new BufferedReader(input);
	
			String line  = bufread.readLine();
		
			while (line != null) {
				line+="\n";
				configlst.add(line);
				line = bufread.readLine();	
			}

			bufread.close();

		} catch (IOException e) {

		}

		for (int i = 0; i < configlst.size(); i++) {
			Object o = configlst.get(i);
			String s = (String)o;
			if (setConfiguration(s) < 0) {
				System.out.println("Bad configuration file line : " + configlst.get(i));
				return;	

			}	
		}
	}

	public int setConfiguration(String configline)
	{

		int idx1 = configline.indexOf(' ');	
		int idx2 = configline.indexOf('\n');	
		if (idx1 >= configline.length() || idx2 < configline.length()-1)
			return -1;	

		String s = configline.substring(0,idx1);
		String s2 = configline.substring(idx1+1,configline.length()-1); 

		if (s2 == "")
			return -1;

		int s2i = Integer.parseInt(s2);//skip newline
			
		switch(s){
		case "bigendian":
			break;
		}


		return 0;
	}

	public void loadBlendFile(String filename) {
		blenderfilereader.load(prefix+filename);	
		xarray = blenderfilereader.getxarray();	
		yarray = blenderfilereader.getyarray();	
		zarray = blenderfilereader.getzarray();	
		carray = blenderfilereader.getcarray();
	}

	
	public void keyPressed(KeyEvent e) {
		int key = e.getKeyCode();
	        GL2 gl = drawabletemp.getGL().getGL2();
	        gl.glClear(GL.GL_COLOR_BUFFER_BIT);

		if (showtitlescreen) {
			if (fadingcounter <= 20) {
				if (key == KeyEvent.VK_X || key == KeyEvent.VK_Z) {
		        	for (int i = 0; i < 30; i++) {
					gl.glClear(GL.GL_COLOR_BUFFER_BIT);
					display(drawabletemp);
					fadingcounter++;
				}
			}	
			else {
				showtitlescreen = false;
				fadingcounter = 0;
			}
			return;
			}
		}
		if (key == KeyEvent.VK_LEFT) {
			System.out.println("LEFT key pressed - rotate");
			update = 1;
       			doupdateleft();
        		render(drawabletemp);
			
		} else if (key == KeyEvent.VK_RIGHT) {
			System.out.println("RIGHT key pressed - rotate");
			update = 1;
       			doupdateright();
        		render(drawabletemp);
		} else if (key == KeyEvent.VK_UP) {
			System.out.println("UP key pressed - translate forward on Z axis");
			update = 2;
        		render(drawabletemp);
		} else if (key == KeyEvent.VK_DOWN) {
			System.out.println("UP key pressed - translate back on Z axis");
			update = 3;
        		render(drawabletemp);
		} else if (key == KeyEvent.VK_X) {
			System.out.println("X key pressed - perspective");
			update = 4;
        		render(drawabletemp);
		} else if (key == KeyEvent.VK_Z) {
			System.out.println("Z key pressed ");
			BulletModel b = new BulletModel(320,200,4);
			bullets.add(b);
		
		} else {
			update = -1;
		}
	}

	public void keyReleased(KeyEvent e) {
		//System.out.println("key released");
	}

	public void keyTyped(KeyEvent e) {
		//System.out.println("key typed");
	}


    public void display(GLAutoDrawable drawable) {


	if (showtitlescreen) {
        		GL2 gl = drawable.getGL().getGL2();
                        Graphics2D g = imgImg.createGraphics();
                        g.drawImage(bufferedImage, null,null);
			g.setColor(Color.blue);
			g.setFont(titlescreenfont);
			g.drawString("Space Odyssey 3D", 20,165);
			g.setColor(Color.gray);
			g.setFont(titlescreenfont2);
			g.drawString("press X key to start", 20,185);
			bb.position(0);
			for (int i = 0; i < 320*240*4; i++) {
				byte b = bb.get(i); 
				if (i%4!=3 && fadingcounter != 0)  {
					b-=2;
					if (b < 0)
						b = 0;
				}	
				bb.put((byte)b);	
			}
                        bb.position(0);
                        //bb.mark();
                        int w = bufferedImage.getWidth();
                        int h = bufferedImage.getHeight();
                        gl.glBindTexture(GL2.GL_TEXTURE_2D, 13);
                        gl.glPixelStorei(GL2.GL_UNPACK_ALIGNMENT, 1);
                        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP);
                        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP);
                        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
                        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
                        gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
                        gl.glTexImage2D (GL2.GL_TEXTURE_2D, 0, GL2.GL_RGBA, w, h, 0, GL2.GL_RGBA,
                                        GL2.GL_UNSIGNED_BYTE, bb);

                        int left = 0;//FIXME fixed
			int top = 0;
                        gl.glEnable(GL2.GL_TEXTURE_2D);
                        gl.glBindTexture (GL2.GL_TEXTURE_2D, 13);
                        gl.glBegin (GL2.GL_POLYGON);
                        gl.glTexCoord2d (0, 0);
                        gl.glVertex2d (left,top);
                        gl.glTexCoord2d(1,0);
                        gl.glVertex2d (left+w, top);
                        gl.glTexCoord2d(1,1);
                        gl.glVertex2d (left+w, top+h);
                        gl.glTexCoord2d(0,1);
                        gl.glVertex2d (left, top+h);
                        gl.glEnd ();
                        gl.glFlush();
    
			return; 
	}

        GL2 gl = drawable.getGL().getGL2();

	gl.glClearColor(0.0f,0.0f,0.0f,1.0f);
        gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT);
   	//doupdate();
	
	if (update < 0) 
		return;

        render(drawable);

	gl.glMatrixMode(GL2.GL_MODELVIEW);
	//NOTE translation must be + rotation methods here under
	gl.glLoadIdentity();
	if (update == 1) {
		gl.glRotatef(theta,2.0f,2.0f,5.0f);
	}
	if (update == 2) {
		dz += 0.1f;
		gl.glRotatef(theta,2.0f,2.0f,5.0f);
		gl.glTranslatef(0.0f,0.0f,dz);//move +1 on z-axis
	}
	if (update == 3) {
		dz -= 0.1f;
		gl.glRotatef(theta,2.0f,2.0f,5.0f);
		gl.glTranslatef(0.0f,0.0f,dz);//move -1 on z-axis
	}
	if (update == 4) {
		gl.glFrustum(-100.0f,100.0f,-100.0f,100.0f, 1.0f, 5.0f);
    	}

	for (int i = 0; i < bullets.size(); i++) {
		Object o = bullets.get(i);
		BulletModel b = (BulletModel)o;
  		b.move(); 
	}
	}


    public void dispose(GLAutoDrawable drawable) {
    }

    public void init(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();
	drawabletemp = drawable;
	gl.glClearColor(0.0f,0.0f,0.0f,0.0f);
	gl.glColor3f(0.0f,0.0f,200.0f);
	gl.glClearDepth(1.0f);
	gl.glEnable(GL2.GL_DEPTH_TEST);
	gl.glDepthFunc(GL2.GL_LEQUAL);
	gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT,GL2.GL_NICEST);
	gl.glShadeModel(GL2.GL_SMOOTH);

              gl.glMatrixMode(GL2.GL_PROJECTION);
                        gl.glLoadIdentity();
                        gl.glOrtho(0, 320, 0, 200, -1, 1);
                        gl.glMatrixMode(GL2.GL_MODELVIEW);
                        gl.glDisable(GL2.GL_DEPTH_TEST);
                        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
                        gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
                        gl.glBlendFunc (GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
                        gl.glEnable (GL2.GL_BLEND);
                        bufferedImage = null;
                        int w = 0;
                        int h = 0;
                        try {
                                bufferedImage = ImageIO.read(new File(prefix+"titlescreen1.png"));
                                w = bufferedImage.getWidth();
                                h = bufferedImage.getHeight();
                        } catch (IOException e) {	
			}
			raster =
                                Raster.createInterleavedRaster (DataBuffer.TYPE_BYTE,
                                                w,
                                                h,
                                                4,
                                                null);
                        ComponentColorModel colorModel=
                                new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                                new int[] {8,8,8,8},
                                                true,
                                                false,
                                                ComponentColorModel.TRANSLUCENT,
                                                DataBuffer.TYPE_BYTE);
                        imgImg =
                                new BufferedImage (colorModel,
                                                raster,
                                                false,
                                                null);

			DataBufferByte imgBuf =
                                (DataBufferByte)raster.getDataBuffer();
                        byte[] imgRGBA = imgBuf.getData();

                        bb = ByteBuffer.wrap(imgRGBA);
	//loadBlendFile("monkeys.blend");
	loadConfiguration(configprefix+"config.txt");
	loadLevel1000(); 
    }

    public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    }

    private void doupdateleft() {
	theta += 1.8f;
   	fraci += 0.32f; 
    }

    private void doupdateright() {
	theta -= 1.8f;
   	fraci -= 0.32f; 
    }


    public float normal(float xx1, float yy1, float zz1, float xx2, float yy2, float zz2)
    {

	return (float)Math.sqrt((float)xx1*xx2 + (float)yy1*yy2 + (float)zz1*zz2);

    } 

    private void render(GLAutoDrawable drawable) {
		if (levelnumber == 1000) {
			renderTerrainGen(drawable);
			renderModelGen(drawable);
		}
	}

    private void renderModel(GLAutoDrawable drawable) {
		renderArrays(drawable);
	}

    private void renderArrays(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();

        gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT);
	int j = 0;
	for (int i = 0; i < xarray.length; i+=3)
	{
		float xx1 = xarray[i];
		float yy1 = yarray[i];
		float zz1 = zarray[i];
		float xx2 = xarray[i+1];
		float yy2 = yarray[i+1];
		float zz2 = zarray[i+1];
		float xx3 = xarray[i+2];
		float yy3 = yarray[i+2];
		float zz3 = zarray[i+2];
		float cc1 = carray[j];
		float cc2 = carray[j];
		float cc3 = carray[j];
		j++;

		float dd1 = 0.0f;
		float dd2 = 0.0f;
		float dd3 = 0.0f;
	        gl.glColor3f(200, cc2, cc3);
	        gl.glBegin(GL.GL_TRIANGLES);
	        gl.glVertex3f(xx1,yy1,zz1);//FIXMES
	        gl.glVertex3f(xx2,yy2,zz2);
	        gl.glVertex3f(xx3,yy3,zz3);
	        gl.glEnd();
    	}
	System.out.println("123> Done drawing model.");
	}

    private void renderModelGen(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();

        gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT);

	for (int j = 0; j < modelpieces.size(); j++) {
		Object o = modelpieces.get(j); 
		ModelGen tp = (ModelGen)o;
 
	for (int i = 0; i < tp.size()-4; i+=tp.padsize()) {//NOTE! -4 for outofbounds 
		if (tp.padsize() == 4) {

			float xx1 = tp.getvertexx(i);
			float yy1 = tp.getvertexy(i);
			float zz1 = tp.getvertexz(i);
			float xx2 = tp.getvertexx(i+1);
			float yy2 = tp.getvertexy(i+1);
			float zz2 = tp.getvertexz(i+1);
			float xx3 = tp.getvertexx(i+2);
			float yy3 = tp.getvertexy(i+2);
			float zz3 = tp.getvertexz(i+2);
			float xx4 = tp.getvertexx(i+3);
			float yy4 = tp.getvertexy(i+3);
			float zz4 = tp.getvertexz(i+3);
	
			//draw a polygon from the map vertices
		        gl.glBegin(GL2.GL_POLYGON);
		        //gl.glBegin(GL2.GL_LINES);
			gl.glColor4f(1,1,0,1);//gradients
		        gl.glVertex3f(xx1,yy1,zz1);
			gl.glColor4f(1,0,1,1);
		        gl.glVertex3f(xx2,yy2,zz2);
			gl.glColor4f(1,1,1,1);
		        gl.glVertex3f(xx3,yy3,zz3);
			gl.glColor4f(0,1,0,0);
		        gl.glVertex3f(xx4,yy4,zz4);
	        
			gl.glEnd();
		}
		else if (tp.padsize() == 3) {
			float xx1 = tp.getvertexx(i);
			float yy1 = tp.getvertexy(i);
			float zz1 = tp.getvertexz(i);
			float xx2 = tp.getvertexx(i+1);
			float yy2 = tp.getvertexy(i+1);
			float zz2 = tp.getvertexz(i+1);
			float xx3 = tp.getvertexx(i+2);
			float yy3 = tp.getvertexy(i+2);
			float zz3 = tp.getvertexz(i+2);
			float cc1 = 0;
			float cc2 = 0;
			float cc3 = 100;
		        //gl.glBegin(GL2.GL_POLYGON);
		        gl.glBegin(GL2.GL_LINES);
			gl.glColor4f(1,1,0,1);
		        gl.glVertex3f(xx1,yy1,zz1);
			gl.glColor4f(1,0,1,1);
		        gl.glVertex3f(xx2,yy2,zz2);
		        gl.glVertex3f(xx3,yy3,zz3);
			gl.glEnd();
		}	 
		else if (tp.padsize() == 2) {
			float xx1 = tp.getvertexx(i);
			float yy1 = tp.getvertexy(i);
			float zz1 = tp.getvertexz(i);
			float xx2 = tp.getvertexx(i+1);
			float yy2 = tp.getvertexy(i+1);
			float zz2 = tp.getvertexz(i+1);
			float cc1 = 0;
			float cc2 = 0;
			float cc3 = 100;
		        //gl.glBegin(GL2.GL_POLYGON);
		        gl.glBegin(GL2.GL_LINE_STRIP);
			gl.glColor4f(1,1,0,1);
		        gl.glVertex3f(xx1,yy1,zz1);
			gl.glColor4f(1,0,1,1);
		        gl.glVertex3f(xx2,yy2,zz2);
			gl.glEnd();
	       //gl.glEnd();
	}
		else if (tp.padsize() == 1) {
			float xx1 = tp.getvertexx(i);
			float yy1 = tp.getvertexy(i);
			float zz1 = tp.getvertexz(i);
			float cc1 = 0;
			float cc2 = 0;
			float cc3 = 100;
		        gl.glBegin(GL2.GL_POLYGON);
		        //gl.glBegin(GL2.GL_LINES);
			gl.glColor4f(1,1,0,1);
		        gl.glVertex3f(xx1,yy1,zz1);
			gl.glEnd();
	       //gl.glEnd();
	}
	}
	}
/*** BLENDER file vertices loading
	int j = 0;
	for (int i = 0; i < xarray.length; i+=3)
	{
		float xx1 = xarray[i];
		float yy1 = yarray[i];
		float zz1 = zarray[i];
		float xx2 = xarray[i+1];
		float yy2 = yarray[i+1];
		float zz2 = zarray[i+1];
		float xx3 = xarray[i+2];
		float yy3 = yarray[i+2];
		float zz3 = zarray[i+2];
		float cc1 = carray[j];
		float cc2 = carray[j];
		float cc3 = carray[j];
		j++;

		float dd1 = 0.0f;
		float dd2 = 0.0f;
		float dd3 = 0.0f;
	        gl.glColor3f(200, cc2, cc3);
	        gl.glBegin(GL.GL_TRIANGLES);
	        gl.glVertex3f(xx1/1000,yy1/1000,zz1/1000);//FIXMES
	        gl.glVertex3f(xx2/1000,yy2/1000,zz2/1000);
	        gl.glVertex3f(xx3/1000,yy3/1000,zz3/1000);
	        gl.glEnd();
    	}
***/
	//gl.glMatrixMode(GL2.GL_MODELVIEW);
	//gl.glFrustum(-100.0f,100.0f,-100.0f,100.0f, 1.0f, 5.0f);//FIXME remove
	//System.out.println("123> Done drawing terrain.");
	}
    private void renderTerrainGen(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();

        gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT);

	for (int j = 0; j < terrainpieces.size(); j++) {
		Object o = terrainpieces.get(j); 
		TerrainPieceBase tp = (TerrainPieceBase)o;
 
	for (int i = 0; i < tp.size()-4; i+=tp.padsize()) {//NOTE! -4 for outofbounds
		if (tp.padsize() == 4) {

			float xx1 = tp.getvertexx(i);
			float yy1 = tp.getvertexy(i);
			float zz1 = tp.getvertexz(i);
			float xx2 = tp.getvertexx(i+1);
			float yy2 = tp.getvertexy(i+1);
			float zz2 = tp.getvertexz(i+1);
			float xx3 = tp.getvertexx(i+2);
			float yy3 = tp.getvertexy(i+2);
			float zz3 = tp.getvertexz(i+2);
			float xx4 = tp.getvertexx(i+3);
			float yy4 = tp.getvertexy(i+3);
			float zz4 = tp.getvertexz(i+3);
			float cc1 = tp.getvertexc(i);
			float cc2 = tp.getvertexc(i+1);
			float cc3 = tp.getvertexc(i+2);
			float cc4 = tp.getvertexc(i+3);

			//draw a polygon from the map vertices
		        gl.glBegin(tp.getGLdraw());
			gl.glColor3f((int)cc1<<24,(int)cc1<<16,(int)cc1<<8);
			//gl.glColor4f(1,1,0,1);//gradients
		        gl.glVertex3f(xx1,yy1,zz1);
			//gl.glColor4f(1,0,1,1);
			gl.glColor3f((int)cc2<<24,(int)cc2<<16,(int)cc2<<8);
		        gl.glVertex3f(xx2,yy2,zz2);
			//gl.glColor4f(1,1,1,1);
			gl.glColor3f((int)cc3<<24,(int)cc3<<16,(int)cc3<<8);
		        gl.glVertex3f(xx3,yy3,zz3);
			//gl.glColor4f(0,1,0,0);
			gl.glColor3f((int)cc4<<24,(int)cc4<<16,(int)cc4<<8);
		        gl.glVertex3f(xx4,yy4,zz4);
	        
			gl.glEnd();
		}
		else if (tp.padsize() == 3) {
			float xx1 = tp.getvertexx(i);
			float yy1 = tp.getvertexy(i);
			float zz1 = tp.getvertexz(i);
			float xx2 = tp.getvertexx(i+1);
			float yy2 = tp.getvertexy(i+1);
			float zz2 = tp.getvertexz(i+1);
			float xx3 = tp.getvertexx(i+2);
			float yy3 = tp.getvertexy(i+2);
			float zz3 = tp.getvertexz(i+2);
			float cc1 = tp.getvertexc(i);
			float cc2 = tp.getvertexc(i+1);
			float cc3 = tp.getvertexc(i+2);
		        gl.glBegin(tp.getGLdraw());
			gl.glColor3f((int)cc1<<24,(int)cc1<<16,(int)cc1<<8);
			//gl.glColor4f(1,1,0,1);
		        gl.glVertex3f(xx1,yy1,zz1);
			gl.glColor3f((int)cc2<<24,(int)cc2<<16,(int)cc2<<8);
			//gl.glColor4f(1,0,1,1);
		        gl.glVertex3f(xx2,yy2,zz2);
			gl.glColor3f((int)cc3<<24,(int)cc3<<16,(int)cc3<<8);
		        gl.glVertex3f(xx3,yy3,zz3);
			gl.glEnd();
		}	 
		else if (tp.padsize() == 2) {
			float xx1 = tp.getvertexx(i);
			float yy1 = tp.getvertexy(i);
			float zz1 = tp.getvertexz(i);
			float xx2 = tp.getvertexx(i+1);
			float yy2 = tp.getvertexy(i+1);
			float zz2 = tp.getvertexz(i+1);
			float cc1 = tp.getvertexc(i);
			float cc2 = tp.getvertexc(i+1);
		        gl.glBegin(tp.getGLdraw());
			//gl.glColor4f(1,1,0,1);
			gl.glColor3f((int)cc1<<24,(int)cc1<<16,(int)cc1<<8);
		        gl.glVertex3f(xx1,yy1,zz1);
			//gl.glColor4f(1,0,1,1);
			gl.glColor3f((int)cc1<<24,(int)cc1<<16,(int)cc1<<8);
		        gl.glVertex3f(xx2,yy2,zz2);
			gl.glEnd();
	}
		else if (tp.padsize() == 1) {
			float xx1 = tp.getvertexx(i);
			float yy1 = tp.getvertexy(i);
			float zz1 = tp.getvertexz(i);
			float cc1 = tp.getvertexc(i);
		        gl.glBegin(tp.getGLdraw());
			//gl.glColor4f(1,1,0,1);
			gl.glColor3f((int)cc1<<24,(int)cc1<<16,(int)cc1<<8);
		        gl.glVertex3f(xx1,yy1,zz1);
			gl.glEnd();
	}
	}
	}
/*** BLENDER file vertices loading
	int j = 0;
	for (int i = 0; i < xarray.length; i+=3)
	{
		float xx1 = xarray[i];
		float yy1 = yarray[i];
		float zz1 = zarray[i];
		float xx2 = xarray[i+1];
		float yy2 = yarray[i+1];
		float zz2 = zarray[i+1];
		float xx3 = xarray[i+2];
		float yy3 = yarray[i+2];
		float zz3 = zarray[i+2];
		float cc1 = carray[j];
		float cc2 = carray[j];
		float cc3 = carray[j];
		j++;

		float dd1 = 0.0f;
		float dd2 = 0.0f;
		float dd3 = 0.0f;
	        gl.glColor3f(200, cc2, cc3);
	        gl.glBegin(GL.GL_TRIANGLES);
	        gl.glVertex3f(xx1/1000,yy1/1000,zz1/1000);//FIXMES
	        gl.glVertex3f(xx2/1000,yy2/1000,zz2/1000);
	        gl.glVertex3f(xx3/1000,yy3/1000,zz3/1000);
	        gl.glEnd();
    	}
***/
	//gl.glMatrixMode(GL2.GL_MODELVIEW);
	//gl.glFrustum(-100.0f,100.0f,-100.0f,100.0f, 1.0f, 5.0f);//FIXME remove
	//System.out.println("123> Done drawing terrain.");
	}
};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.util.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;

public class ModelBase extends ModelGen {
	int GLdrawMethod; 
	public ModelBase(int ww, int hh, int padsz, int GLdraw) {
		super(ww,hh,padsz);	
		GLdrawMethod = GLdraw;
	}

	public int getGLdraw()
	{
		return GLdrawMethod;
	}
};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.nio.ByteBuffer;

import javax.imageio.ImageIO;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;

import java.awt.Frame;
import java.awt.event.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;
import javax.media.opengl.glu.GLU;
import java.util.*;
import java.io.*;
import javablender.*;
import java.util.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;

/*
 * class ModelGen :
 */

public class ModelGen {
protected LinkedList vertices = new LinkedList();
private int padsize = 4;
private int width = 48;
private int height = 48;
private float x = 0.0f;
private float y = 0.0f;
private float z = 0.0f;


/*
 * embedded classes
 */
	protected class Vertex
	{
		protected float x,y,z;
		public Vertex(float xx, float yy, float zz)
		{
			x = xx;
			y = yy;
			z = zz;
		}

		public float getx()
		{
			return x;
		}
	
		public float gety()
		{
			return y;
		}
	
		public float getz()
		{
			return z;
		}
	
	};

/*
 * Constructors
 */	
	public ModelGen(int ww, int hh, int pad)
	{
		width = ww;
		height = hh;
		//read pad vertices at oncefor storing a polygon
		padsize = pad;
		

	}

/*
 * math functionality
 */

    public float normal(float xx1, float yy1, float zz1, float xx2, float yy2, float zz2)
    {

	return (float)Math.sqrt((float)xx1*xx2 + (float)yy1*yy2 + (float)zz1*zz2);

    } 

/*
 * drawing primitives e.g. sphere, polygons
 */


	public void generatesphere(float radius, int pieces)
	{
		padsize = 3;
		int meridians = 3*pieces;
		int parallels = 3*pieces;

		for (float theta = 0; theta < Math.PI; theta += Math.PI/meridians) {
			for (float phi = 0; phi < 2*Math.PI; phi += 2*Math.PI/parallels) {

				vertices.add(new Vertex((float)(x+Math.cos(theta)*Math.sin(phi)*radius),
							(float)(y+Math.sin(theta)*Math.sin(phi)*radius),
							(float)(z+Math.cos(phi)*radius)));		
			}	
		}
	}

/*
 * accessors
 */
	public float getvertexx(int index)
	{
		Object o = vertices.get(index);
		Vertex v = (Vertex)o;
		float xx = v.getx();
		return xx;
	} 
	public float getvertexy(int index)
	{
		Object o = vertices.get(index);
		Vertex v = (Vertex)o;
		float yy = v.gety();
		return yy;
	} 
	public float getvertexz(int index)
	{
		Object o = vertices.get(index);
		Vertex v = (Vertex)o;
		float zz = v.getz();
		return zz;
	} 

	public int size()
	{
		return vertices.size();
	}

	public int padsize()
	{
		return padsize;
	}
};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.util.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;

public class Model extends ModelBase {

	public Model(int ww, int hh, int padsz, int GLdraw) {
		super(ww,hh,padsz,GLdraw);	
	}

	public void loadDefaultModel()
	{

	}

};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.nio.ByteBuffer;

import javax.imageio.ImageIO;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
//import javax.media.opengl.GLCanvas;
//import javax.media.opengl.GLEventListener;
//import javax.swing.JFrame;

import java.awt.Frame;
import java.awt.event.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;
import javax.media.opengl.glu.GLU;
import java.util.*;
import java.io.*;
import javablender.*;
import java.util.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;

/*
 * class TerrainGen :
 * generates maps of polygons and contains
 * drawing primitives for map building
 * This is the base class of a TerrainPieceBase
 */

public class TerrainGen {
private LinkedList vertices = new LinkedList();
private int index = 0;
private int width = 320;
private int height = 200;
private int padsize = 4;
//bb is the work buffer for image files and texturemapping
private ByteBuffer bb;
private String prefix = "./pics/";
private boolean bigendian = true;

/*
 * embedded classes
 */
	protected class Vertex
	{
		protected float x,y,z,c;
		public Vertex(float xx, float yy, float zz)
		{
			x = xx;
			y = yy;
			z = zz;
			c = 200;
		}

		public Vertex(float xx, float yy, float zz, float cc)
		{
			x = xx;
			y = yy;
			z = zz;
			c = cc;
		}

		public float getc()
		{
			return c;
		}
		public float getx()
		{
			return x;
		}
	
		public float gety()
		{
			return y;
		}
	
		public float getz()
		{
			return z;
		}
	
	};

/*
 * Constructors
 */	
	public TerrainGen(int ww, int hh, int pad, boolean bige)
	{
		width = ww;
		height = hh;
		//read pad vertices at oncefor storing a polygon
		padsize = pad;
		bigendian = bige;

	}

/*
 * math functionality
 */

    public float normal(float xx1, float yy1, float zz1, float xx2, float yy2, float zz2)
    {

	return (float)Math.sqrt((float)xx1*xx2 + (float)yy1*yy2 + (float)zz1*zz2);

    }

/* 
 * ByteBuffer functionality
 */

	
	public void gfxfiletobytebuffer(String gfxfilename)
	{ 
		BufferedImage bufferedImage = null;
		int w=0,h=0;
		try {
			bufferedImage = ImageIO.read(new File(prefix+gfxfilename));
			w = bufferedImage.getWidth();
			h = bufferedImage.getHeight();
		} catch (IOException e) {}

		WritableRaster raster =
                                Raster.createInterleavedRaster (DataBuffer.TYPE_BYTE,
                                                w,
                                                h,
                                                4,
                                                null);
                ComponentColorModel colorModel =
                                new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                                new int[] {8,8,8,8},
                                                true,
                                                false,
                                                ComponentColorModel.TRANSLUCENT,
                                                DataBuffer.TYPE_BYTE);
                 BufferedImage imgImg =
                                new BufferedImage (colorModel,
                                                raster,
                                                false,
                                                null);

                 DataBufferByte imgBuf =
                                (DataBufferByte)raster.getDataBuffer();
		 byte[] imgRGBA = imgBuf.getData();

                 bb = ByteBuffer.wrap(imgRGBA);
	}

/*
 * gfx file e.g. jpg or png functionality
 */

	public void gfxfiletovertices(float xx, float yy, float zz, float ww, float hh, String gfxfilename)
	{
		gfxfiletobytebuffer(gfxfilename);	
		bb.position(0);
		for (int j = 0; j < 100; j++) {
			for (int i = 0; i < 63; i+=4) {
				byte b = bb.get(j*100+i);
				byte b2 = bb.get(j*100+i+1);
				byte b3 = bb.get(j*100+i+2);
				byte b4 = bb.get(j*100+i+3);
				if (bigendian)
					vertices.add(new Vertex(xx+i,yy+j,zz,b*8*8*8+b2*8*8+b3*8+b4));
				else
					vertices.add(new Vertex(xx+i,yy+j,zz,b+b2*8+b3*8*8+b4*8*8*8));
				
			}
		}
		
	}
/*
 * drawing primitives e.g. squares, polygons
 */

	public void generatecircle(float r)
	{
		padsize = 3;

		float increment = (float)(2*Math.PI/48);//in 48 pieces	
		float cx = 0.0f;
		float cy = 0.0f;
		float radius = r;
	
		for (float angle = 0; angle < 2*Math.PI; angle+=increment) {
			vertices.add(new Vertex(cx,cy,0.0f));
			vertices.add(new Vertex((float)(cx+Math.cos(angle)*radius),(float)(cy+Math.sin(angle)*radius),0.0f));
			vertices.add(new Vertex((float)(cx+Math.cos(angle + increment)*radius),(float)(cy+Math.sin(angle + increment)*radius),0.0f));
		}
	}

	public void generatetwothirdcylinder(float r, float length)
	{
		padsize = 2;

		float increment = (float)(2*Math.PI/48);//in 48 pieces	
		float cx = 0.0f;
		float cy = 0.0f;
		float radius = r;

		for (float zz = -length/2; zz < length/2; zz+=0.2f) {
			generatetwothirdcircle(r,zz);
			//generate lines	
			vertices.add(new Vertex((float)(cx-Math.cos(-Math.PI/4)*radius),(float)(cy+Math.cos(Math.PI+Math.PI/4)*radius),zz));
			vertices.add(new Vertex((float)(cx+Math.cos(Math.PI/4)*radius),(float)(cy+Math.cos(Math.PI+Math.PI/4)*radius),zz));

		}	
		for (float zz = -length/2; zz < length/2; zz+=0.2f) {
			//generate left circle connections	
			vertices.add(new Vertex((float)(cx-Math.cos(-Math.PI/4)*radius),(float)(cy+Math.cos(Math.PI+Math.PI/4)*radius),zz));
			zz+=0.2f;
			vertices.add(new Vertex((float)(cx-Math.cos(-Math.PI/4)*radius),(float)(cy+Math.cos(Math.PI+Math.PI/4)*radius),zz));
				
		}
		for (float zz = -length/2; zz < length/2; zz+=0.2f) {
			//generate right circle connections	
			vertices.add(new Vertex((float)(cx+Math.cos(Math.PI/4)*radius),(float)(cy+Math.cos(Math.PI+Math.PI/4)*radius),zz));
			zz+=0.2f;
			vertices.add(new Vertex((float)(cx+Math.cos(Math.PI/4)*radius),(float)(cy+Math.cos(Math.PI+Math.PI/4)*radius),zz));
				
		}
	}

	public void generatehalfcylinder(float r, float length)
	{
		padsize = 2;

		float increment = (float)(2*Math.PI/48);//in 48 pieces	
		float cx = 0.0f;
		float cy = 0.0f;
		float radius = r;

		for (float zz = -length/2; zz < length/2; zz+=0.2f) {
			generatehalfcircle(r,zz);
			//generate lines	
			vertices.add(new Vertex(cx-radius,cy,zz));
			vertices.add(new Vertex(cx+radius,cy,zz));
		}	
	}

	public void generatehalfcircletest(float r, float zz)
	{
		padsize = 3;

		float increment = (float)(2*Math.PI/48);//in 48 pieces	
		float cx = 0.0f;
		float cy = 0.0f;
		float radius = r;
	
		for (float angle = 0; angle < Math.PI; angle+=increment) {
			vertices.add(new Vertex(cx,cy,0.0f));
			vertices.add(new Vertex((float)(cx+Math.cos(angle)*radius),(float)(cy+Math.sin(angle)*radius),zz));
			vertices.add(new Vertex((float)(cx+Math.cos(angle + increment)*radius),(float)(cy+Math.sin(angle + increment)*radius),zz));
		}
	}
 
	public void generatetwothirdcircle(float r, float zz)
	{
		padsize = 2;

		float increment = (float)(2*Math.PI/(48*3));//in 48 pieces	
		float cx = 0.0f;
		float cy = 0.0f;
		float radius = r;
		float angle = 0;
	
		for (angle = (float)(-Math.PI/4); angle < Math.PI+Math.PI/4; angle+=increment) {
			vertices.add(new Vertex((float)(Math.cos(angle)*radius),(float)(Math.sin(angle)*radius),zz));
			vertices.add(new Vertex((float)(Math.cos(angle + increment)*radius),(float)(Math.sin(angle + increment)*radius),zz));
		}
	}
	public void generatehalfcircle(float r, float zz)
	{
		padsize = 2;

		float increment = (float)(2*Math.PI/(48*3));//in 48 pieces	
		float cx = 0.0f;
		float cy = 0.0f;
		float radius = r;
		float angle = 0;
	
		for (angle = 0; angle < Math.PI; angle+=increment) {
			vertices.add(new Vertex((float)(Math.cos(angle)*radius),(float)(Math.sin(angle)*radius),zz));
			vertices.add(new Vertex((float)(Math.cos(angle + increment)*radius),(float)(Math.sin(angle + increment)*radius),zz));
		}
	}
 
	public void generatecylindertest(float r)
	{
		padsize = 3;
		float radius = r;
		float increment = (float)(2*Math.PI/(32*3));//in 48 pieces	
		for (float angle = 0; angle < Math.PI; angle+=increment) {
			vertices.add(new Vertex((float)(Math.cos(angle)*radius),(float)(Math.sin(angle)*radius),0.0f));
			System.out.println("x="+Math.cos(angle)*radius+" y="+Math.sin(angle)*radius);
			angle += increment;
			vertices.add(new Vertex((float)(Math.cos(angle)*radius),(float)(Math.sin(angle)*radius),0.0f));
			System.out.println("x="+Math.cos(angle)*radius+" y="+Math.sin(angle)*radius);
			angle += increment;
			vertices.add(new Vertex((float)(Math.cos(angle)*radius),(float)(Math.sin(angle)*radius),0.0f));
			System.out.println("x="+Math.cos(angle)*radius+" y="+Math.sin(angle)*radius);
		

	}
				


	}


	public void trapezoidtexturemap(ByteBuffer bb2, int capacity, int ww, int hh, int leftxoffset, int rightxoffset)
	{
			int xoffset = 40;	
			int woffset = 40;	
			for (int j = 0; j < hh; j++) {
			int pos1 = j*hh;
                        bb2.position(0);
			for (int i = 0; i < ww; i++) {
				
				byte b = bb2.get(i*(int)(ww/hh)+j*ww);
				if (i == 0)
					bb2.position(pos1+leftxoffset-leftxoffset/width*j);
				else if (i >= rightxoffset)
					continue;

				bb2.put((byte)b);

			}
			}
                        bb2.position(0);
	}

	public void generatedowntiltedsquare(float xx, float yy, float ww, float hh, float d1)
	{
		padsize = 4;
		float zz = 0;
		vertices.add(new Vertex((float)xx,(float)yy,zz+d1));
		vertices.add(new Vertex((float)xx+ww,(float)yy,zz));
		vertices.add(new Vertex((float)xx+ww,(float)yy+hh,zz));
		vertices.add(new Vertex((float)xx,(float)yy+hh,zz));
	}

	public void generateuptiltedsquare(float xx, float yy, float ww, float hh, float d1)
	{
		padsize = 4;
		float zz = 0;
		vertices.add(new Vertex((float)xx,(float)yy,zz-d1));
		vertices.add(new Vertex((float)xx+ww,(float)yy,zz));
		vertices.add(new Vertex((float)xx+ww,(float)yy+hh,zz));
		vertices.add(new Vertex((float)xx,(float)yy+hh,zz));
	}

	public void generatetiltedsquaretest1(float xx, float yy, float ww, float hh, float d1, float d2, float d3, float d4)
	{
		padsize = 4;
		float dx1 = 0;
		float dx2 = 0;
		float dx3 = 0;
		float dx4 = 0;
		float dz1 = 0;
		float dz2 = 0;
		float dz3 = 0;
		float dz4 = 0;
		vertices.add(new Vertex((float)xx,(float)yy+hh+d1,dz1));
		vertices.add(new Vertex((float)xx+ww,(float)yy+hh,dz1));
		vertices.add(new Vertex((float)xx+ww,(float)yy,dz1));
		vertices.add(new Vertex((float)xx,(float)yy+hh,dz1));
	}

	public void generatesquare(float xx, float yy, float ww, float hh)
	{
		padsize = 4;

		vertices.add(new Vertex((float)xx,(float)yy,0.0f));
		vertices.add(new Vertex((float)xx+ww,(float)yy,0.0f));
		vertices.add(new Vertex((float)xx+ww,(float)yy+hh,0.0f));
		vertices.add(new Vertex((float)xx,(float)yy+hh,0.0f));
		
	}

	public void generaterectangle(float xx, float yy, float ww, float hh)
	{
		padsize = 4;

		vertices.add(new Vertex((float)xx,(float)yy,0.0f));
		vertices.add(new Vertex((float)xx+ww,(float)yy,0.0f));
		vertices.add(new Vertex((float)xx+ww,(float)yy+hh,0.0f));
		vertices.add(new Vertex((float)xx,(float)yy+hh,0.0f));
		
	}

	public void generaterectangularpillar(float xx, float yy, float zz, float ww, float hh)
	{
		padsize = 4;
	//	generaterectangle(xx,yy,ww,hh);
		vertices.add(new Vertex((float)xx,(float)yy,ww));
		vertices.add(new Vertex((float)xx+ww,(float)yy,ww));
		vertices.add(new Vertex((float)xx+ww,(float)yy+hh,ww));
		vertices.add(new Vertex((float)xx,(float)yy+hh,ww));
	
		vertices.add(new Vertex((float)xx,(float)yy+ww,ww));
		vertices.add(new Vertex((float)xx+ww,(float)yy+ww,ww));
		vertices.add(new Vertex((float)xx+ww,(float)yy+hh+ww,ww));
		vertices.add(new Vertex((float)xx,(float)yy+hh+ww,ww));

		//put pixels in vertices array
		gfxfiletovertices(xx,yy,zz,ww,hh,"pillar-63x100-1.png");


	}



	/*
	 * Function : generatetiltedsquarestop :
	 * generate a square with 4 adjacent squares lower with 
	 * lower outer corners. 
	 * the 4 outer outer corners are length down d1, etc. 
	 */
	public void generatetiltedsquarestop(int xx, int yy, int ww, int hh, int dz1, int dz2, int dz3, int dz4)
	{
		generatedowntiltedsquare(-xx,-yy,ww,hh,dz1);
		generatedowntiltedsquare(0,-xx,-ww,hh,dz2);//NOTE negative width;
		generatedowntiltedsquare(-xx,0,ww,hh,dz3);
		generatedowntiltedsquare(0,0,-ww,hh,dz4);
	}


	public void generatemap1()
	{
	
		for (int i = -10; i < 10; i+=10) {
		int j;
		for (j = -16; j < 16; j+=10) {
				generatedowntiltedsquare(i,-j,1,1,3);//FIXME better width and height 
				generatedowntiltedsquare(0,-j,-1,1,3);//NOTE negative width;
				generatedowntiltedsquare(-i,0,1,1,3);
				generatedowntiltedsquare(0,0,-1,1,3);
			}
			j = -100;	
		}
	}

	public void generatemap2()
	{
	
		for (int i = 0; i < 10; i++) {
			generatetiltedsquarestop(i,0,1,1,3*i,3*i,3*i,3*i);//FIXME better width and height 
			//generatedowntiltedsquare(0,-j,-1,1,3);//NOTE negative width;
			//generatedowntiltedsquare(-i,0,1,1,3);
			//generatedowntiltedsquare(0,0,-1,1,3);
		}
	}


	public float getvertexc(int index)
	{
		Object o = vertices.get(index);
		Vertex v = (Vertex)o;
		float cc = v.getc();
		return cc;
	} 
	public float getvertexx(int index)
	{
		Object o = vertices.get(index);
		Vertex v = (Vertex)o;
		float xx = v.getx();
		return xx;
	} 
	public float getvertexy(int index)
	{
		Object o = vertices.get(index);
		Vertex v = (Vertex)o;
		float yy = v.gety();
		return yy;
	} 
	public float getvertexz(int index)
	{
		Object o = vertices.get(index);
		Vertex v = (Vertex)o;
		float zz = v.getz();
		return zz;
	} 

	public int size()
	{
		return vertices.size();
	}

	public int padsize()
	{
		return padsize;
	}
};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.util.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;

public class TerrainPieceBase extends TerrainGen {
	int GLdrawMethod; 
	public TerrainPieceBase(int ww, int hh, int padsz, int GLdraw, boolean bige) {
		super(ww,hh,padsz,bige);	
		GLdrawMethod = GLdraw;
	}

	public int getGLdraw()
	{
		return GLdrawMethod;
	}
};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.util.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;

public class TerrainPiecePillar extends TerrainPieceBase {

	public TerrainPiecePillar(float xx, float yy, float zz, int ww, int hh, int padsz, int GLdraw) {
		super(ww,hh,padsz,GLdraw,true);
			
		generaterectangularpillar(xx,yy,zz,ww,hh);	
	}
};
package game;
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.util.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.*;

public class TerrainPieceWalkingTube extends TerrainPieceBase {

	public TerrainPieceWalkingTube(int ww, int hh, int padsz,int GLdraw) {
		super(ww,hh,padsz,GLdraw,true);	
		generatetwothirdcylinder(10.0f,10);	
	}
};


\end{verbatim}
\end{mylisting}


\section{\large Conclusion}


\bibliographystyle{plain}
\bibliography{plasmascreen} % refs.bib

\end{document}

%%




